from kunlun import lib

# 获取事件日志接口
log = lib.get_event_logger()


class BURN:
    uut = None

    def setup(self):
        container_name = lib.get_container_name()
        log.debug(container_name)
        lib.add_test_data(sernum="1234567890", uuttype="DEMO", area="DEMO")

    def run_test1(self):
        lib.set_display1("机型: 1234567890123456")
        lib.set_display2("料号: 1234567890123456")
        lib.set_display3("Slot ID: 1234567890123456")
        lib.set_display4("流水号: 1234567890123456")
        lib.set_display5("WO: 1234567890123456")
        lib.set_display6("其他: 1234567890123456")
        self.uut = lib.conn.REF
        self.uut.open()
        self.uut.send("pwd\r", expect=[">", "$"], timeout=10)
        self.uut.send("ls\r", expect=[">", "$"], timeout=10)
        return

    def run_test2(self):
        log.debug("run test2")
        self.uut.send("python\r", expect=">>>", timeout=10)
        self.uut.send("import sys\r", expect=">>>", timeout=10)
        self.uut.send("sys.platform\r", expect=">>>", timeout=10)
        log.debug(self.uut.buf)
        if "linux" not in self.uut.buf:
            raise Exception("platform should be [linux], go to fail")
        self.uut.send("exit()\r", expect=[">", "$"], timeout=10)
        return

    def teardown(self):
        log.debug("run test3")
        self.uut.close()
        return


# 定义入口函数, 每个文件只有一个入口函数。
def main_sequence():
    case = BURN()
    container_list = [f"BURN:DUT{i:02}" for i in range(1, 33)]
    log.debug(container_list)

    if lib.get_container_name() == "BURN:START":
        log.debug("start test")
        lib.start_test(container_list)
        return

    if lib.get_container_name() == "BURN:STOP":
        lib.stop_test(container_list)
        return

    if lib.get_container_name() == "BURN:DEPOSIT":
        lib.deposit_test(container_list)
        return

    seq = lib.get_sequence_definition("MAIN SEQ")
    seq.add_step(case.setup, name="setup")
    seq.add_step(case.run_test1, name="run test1")
    seq.add_step(case.run_test2, name="run test2")
    seq.add_step(case.teardown, name="teardown")
    # 返回根序列
    return seq
